// 增加管理员
controllers.controller('addBackMemberCtrl', ['$scope', '$http', '$rootScope', '$modal', '$window', 'Member', 'AlertService', 'Upload',
    function ($scope, $http, $rootScope, $modal, $window, Member, AlertService, Upload) {

        $scope.resetCurrentPageName("会员维护");
        $scope.utils = Food.utils;
        $scope.member = {};
        $scope.memberList = Member.adminMemberList;

        $scope.pageSize = 20;
        $scope.currentPage = 1;

        $scope.queryList = function () {
            Member.queryAdminList($scope.currentPage, $scope.pageSize, function () {
            });
        };
        $scope.queryList();

        $scope.pcRegister = function () {
            Member.pcRegister($scope.member, function () {

            });
        };
        $scope.deleteMem = function (memberId) {
            Member.deleteMem(memberId, function () {

            });
        };

        var operateTemplate = "<button class='btn btn-primary btn-sm' ng-click='grid.appScope.deleteMem(row.entity.memberId)'>删除</button>";

        $scope.gridOptions = {
            data: 'memberList',
            enableColumnMenus: false,
            enableColumnResizing: true,
            columnDefs: [

                {
                    field: 'memberId',
                    displayName: 'ID'
                },
                {
                    field: 'memberName',
                    displayName: '账号',
                    width: "10%"
                },
                {
                    field: 'memberPwd',
                    displayName: '密码'
                },
                {
                    field: 'state',
                    displayName: '状态'
                },
                {
                    field: 'id',
                    displayName: '操作',
                    width: "10%",
                    cellTemplate: operateTemplate
                }
            ]
        };

    }]);

controllers.controller('memberListCtrl', ['$scope', '$http', '$rootScope', '$modal', '$window', 'Member', 'AlertService',
    function ($scope, $http, $rootScope, $modal, $window, Member, AlertService) {

        $scope.resetCurrentPageName("会员维护");
        $scope.utils = Food.utils;
        $scope.member = {};
        $scope.memberList = Member.memberList;

        $scope.pageSize = 20;
        $scope.currentPage = 1;

        $scope.queryList = function () {
            Member.queryMemberList($scope.member, function () {
            });
        };
        $scope.queryList();

        $scope.findLowMem = function (memberId) {
            Member.findLowMem(memberId, function () {
                if ($scope.memberList.length == 0) {
                    AlertService.addAlert({type: 'danger', msg: '当前用户没有下线用户! '}, 2000);
                }
            });
        };

        var operateTemplate = "<button class='btn btn-primary btn-sm' ng-click='grid.appScope.findLowMem(row.entity.memberId)'>查看下线</button>";

        $scope.gridOptions = {
            data: 'memberList',
            enableColumnMenus: false,
            enableColumnResizing: true,
            columnDefs: [

                {
                    field: 'memberId',
                    displayName: 'ID'
                },
                {
                    field: 'memberName',
                    displayName: '账号',
                    width: "10%"
                },
                {
                    field: 'mobilePhone',
                    displayName: '手机号'
                },
                {
                    field: 'timeAdd',
                    displayName: '注册时间',
                    cellFilter: "date:'yyyy-MM-dd hh:mm:ss'"
                },
                {
                    field: 'id',
                    displayName: '操作',
                    width: "10%",
                    cellTemplate: operateTemplate
                }
            ]
        };

    }]);

